
capture log close

set more off
set matsize 10000

use rep_final, clear

	*noncitizens
	keep if cit==0
	*married last year, currently still married with spouse present
	keep if marrinyr==2 & married==1 
	*spouse info is avail.
	drop if citizen_sp==.

* Define control variables 

	local demog "age age2 male yreduc i.racegr"
	local imm "ysm i.bpl " 
	local fe "i.statefip i.yrmarr "
		
	local full "`demog' `imm' `fe' "
	
* Use yrmarr to measure time treatment because individuals are surveyed throughout the year
	*marriage in the past 12 months could mean this year or last year.
	
	g post1=(yrmarr>=2013 & yrmarr<=2016)
	g post2=(yrmarr>=2017)
	
	g treatpost1=treatgr*post1
	g treatpost2=treatgr*post2
	
	
**********************************************************************************
*Table 2 - Panel A	
	
	local a=1 
	
	foreach controlgr of varlist controlgrdacacutoff controlgrdaca_agematch ///
								controlgrchildimm controlgrdacahs  {
		
		foreach depvar of varlist cit_sp  {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			display "Control group: `controlgr' "		
			
			display "--------------------------------------"
		

			*treatpost1 and treatpost2 both compare to pre-period
			
			reg `depvar' treatpost1 treatpost2 treatgr `full'  ///
				if daca==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto e`a'		
			
			local a=`a'+1
			}
			
		*dep var mean
	
		sum cit_sp [fweight=perwt] if e(sample) 
		
		}
			*Make table 
			
			*using only one treatment period: post 2012
			
			esttab e1 e2 e3 e4 ///
					using table2_panelA.csv, se  ///
					mtitles("DACA-Ineligible Missing cutoffs" ///
							"DACA-Ineligible Age matched" ///
							"DACA-Ineligible Child Immigrants" ///
							"DACA-Ineligible with HS/GED" ) ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace
			
		
******************************************************************************
*Table 2 - Panel B

		*redefine daca as among undocumented imm - dacai==1
		
		local a=1
	
		foreach controlgr of varlist controlgrdaca controlgrdacacutoff controlgrdaca_agematch ///
								controlgrchildimm controlgrdacahs  {
		
		foreach depvar of varlist cit_sp  {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			display "Control group: `controlgr' "
			
			
			display "--------------------------------------"
		

			*treatpost1 and treatpost2 both compare to pre-period
			
			reg `depvar' treatpost1 treatpost2 treatgr `full'  ///
				if dacai==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto e`a'
			
			local a=`a'+1
		
		*dep var mean
	
		sum cit_sp [fweight=perwt] if e(sample) 
		
			}
			

		
		}
			*Make table 
						
			esttab e1 e2 e3 e4 e5 ///
					using table2_panelB.csv, se  ///
					mtitles("Non-DACA Undocumented" ///
							"DACA-Ineligible Missed cutoff" ///
							"DACA-Ineligible Age matched" ///
							"DACA-Ineligible Child Immigrants" ///
							"DACA-Ineligible with HS/GED") ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace
		
*********************************************************************************
*Table 2 Panel C
			
*Hispanic Sample
	
	keep if hispanic==1
	
	
	local a=1
	foreach controlgr of varlist controlgrdaca  controlgrdacacutoff  ///
							controlgrdaca_agematch controlgrchildimm  controlgrdacahs {

		foreach depvar of varlist cit_sp  {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			
			
			display "--------------------------------------"
		
			
			reg `depvar' treatpost1 treatpost2 treatgr `full'  ///
				if daca==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto e`a'	


			local a=`a'+1
			
			*dep var mean
			sum cit_sp  [fweight=perwt] if e(sample)
		
			}

			
		}

			*Make table 
			
			esttab e1 e2 e3 e4 e5 ///
					using table2_panelC.csv, se  ///
					mtitles("Non-DACA Undocumented" ///
							"DACA-Ineligible Missed cutoff" ///
							"DACA-Ineligible Age matched" ///
							"DACA-Ineligible Child Immigrants" ///
							"DACA-Ineligible with HS/GED") ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace		
